<!DOCTYPE html>
<html>
<#include "include/header.html"/>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<body>
<div class="page">
	<div class="content m">
	<#if commodity_type == '01' >
			<#if sendAddress?? > 
			<div class="mod_addr">
			<div class="t">送至</div>
			<div class="address">${sendAddress.province_name!}${sendAddress.city_name!}${sendAddress.country_name!}${sendAddress.geography_location!}</div>
			<div class="name">${sendAddress.receiver_name!}${sendAddress.telephone!}</div>
			</div>
			<#else>
			<div class="mod_addr">
			<div class="t">送至</div>
			<div class="address"></div>
			<div class="name"></div>
			</div>
			</#if>
			</#if>
		<div class="cart_confirm">
		<#list commodityList as a>
			<div class="item">
			<#if a.commodity_logo??>
				<img src="${server_uri!}${a.commodity_logo!}" class="pic">
				<#else>
				<img src="" class="pic">
				</#if>
				<div class="title">${a.commodity_name!}</div>
				<div class="price">￥${a.per_price!}</div>
				<div class="attr">型号:${a.version_type!}</div>
				<div class="attr">数量:${a.buy_num!}</div>
			</div>
			</#list>
		</div>
		
		<div class="mod_attr">
			<div class="item">
				<div class="fl">配送方式</div>
				<div class="fr">商家配送</div>
			</div>
		</div>
		
		<div class="mod_attr mod_large">
			<div class="item">
				<div class="fl">商品总额</div>
				<div class="fr">￥<span class="red" >${total_price!}</span></div>
			</div>
			<#if commodity_type == '01' >
			<div class="item">
				<div class="fl">运费</div>
				<div class="fr">￥<span class="red" id="send_cost">15</span></div>
			</div>
			</#if>
		</div>		
	</div>

	<div class="footer">
		<div class="btn_group tab_c tab_c1">
			<div class="total" style="font-size:20px;">合计：￥<span id="totalPrice"></span></div>
			<a href="javascript:void(0);" class="btn btn_red btn_submit" onclick="submitOrder();">提交订单</a>
		</div>
	</div>
	
</div>
</body>
<script type="text/javascript">
$(function(){
var from_user="${from_user!}";
if(from_user == "" || from_user == null){
 from_user=$.cookie('from_user9');
}
$.cookie('from_user9',from_user, { expires: 365 });
var price="${total_price!}";
var send_cost="0";
<#if commodity_type == '01' >
send_cost=$("#send_cost").html()
send_cost=send_cost.replace("￥","");
</#if>
price=FloatAdd(parseFloat(price),parseFloat(send_cost));
$("#totalPrice").html(price);
var address_id="";
var commodity_type="${commodity_type!}";
if(commodity_type == 01){
<#if sendAddress??>
address_id="${sendAddress.id!}";
</#if>
}
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
		submitOrder = function() {
		if(commodity_type == 01){
		if(address_id=='' || address_id==undefined || address_id==null){
		dialog('#ok',3000,"送货地址不能为空");
		   return;
           }
           }
        $(".btn_submit").removeAttr("onclick");
        $(".btn_submit").removeClass("btn_red");
        $(".btn_submit").addClass(".btn_gray");
        $(".btn_submit").removeAttr("onclick");
		$.post("${ctx}/pay/createWXPayOrder",{
		    from_user:from_user,
			buy_ids:"${buy_ids!}",
			commodity_type:"${commodity_type!}",
			totalPrice:price,
			address_id:address_id,
			send_cost:send_cost,
			type:"01",
			dispatch_mode:"01"
		},function(data){
		 if(data.code==0){
					//进行支付，后期增加支付品牌判断
					pay_money=data.pay_money;
					WeixinJSBridge.invoke('getBrandWCPayRequest',{
						"appId" : data.params.appId, //公众号名称，由商户传入
						"timeStamp" : data.params.timeStamp, //时间戳
						"nonceStr" : data.params.nonceStr, //随机串
						"package" : data.params.packageStr,
						"signType" : "MD5", //微信签名方式:1.sha1
						"paySign" : data.params.paySign ////微信签名
					},function(res){
					 	if(res.err_msg == "get_brand_wcpay_request:ok" ) {
							$.post("${ctx}/pay/subWeiXinPay",{
								order_no:data.order_id,
								commodity_id:data.commodity_id,
								from_user:from_user,
								buy_id:data.buy_id,
								pay_money:pay_money,
								total_id:data.total_id,
								commodity_type:data.commodity_type,
								prepay_id:data.params.packageStr
							},function(data){
								if(data.code==0){
								if(data.order_type == 01){
									window.location.href="${ctx}/mine/orderDetails?from_user="+from_user+"&order_status=02&type=1";
							       }else{
							        window.location.href="${ctx}/mine/MyOneBuy?from_user="+from_user+"&status=01&type=1&is_win=";
							       }
							}else{
								 dialog('#ok',3000,data.msg);
								} 
							});
							
					 	}else{
					 		dialog('#ok',3000,"支付失败："+res.err_msg);
					 		if(commodity_type == 01){
									window.location.href="${ctx}/mine/orderDetails?from_user="+from_user+"&order_status=01&type=1";
							       }
					 	}
					 	
				  })
				  }else{
					   dialog('#ok',3000,data.msg);
					   }
		},'json'); 
		}
		})
		
		$(".mod_addr").click(function(){
		window.location.href="${ctx}/mine/getAddr?from_user="+from_user+"&buy_id="+"${buy_ids!}"+"&commodity_type="+"${commodity_type!}"+"&forward_type=02"+"&is_order=01";
		})
});
</script>
</html>